using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.IO.Ports;

namespace Thesis_NCDat
{
    public partial class formuartconnect : DevComponents.DotNetBar.RibbonForm
    {
        public formuartconnect()
        {
            InitializeComponent();
        }

     int _intlen = 0; //luu gia tri so cong Com trong may tinhh
 

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            {
                string[] ports = SerialPort.GetPortNames(); //lay tat ca cong COM trong PC
                if (_intlen != ports.Length)
                {
                    _intlen = ports.Length;
                    CbSecCom.Items.Clear();
                    for (int j = 0; j < _intlen; j++)
                    {
                        CbSecCom.Items.Add(ports[j]);
                    }
                }
            }
        }

        private void ButDefault_Click_1(object sender, EventArgs e)
        {
            CbSecCom.Text = "COM1";
            CbBaudRate.Text = "9600";
            CbDatabits.Text = "8";
            CbStopbits.Text = "1";
            CbParity.Text = "None";
        }

        private void ButOk_Click_1(object sender, EventArgs e)
        {
            //checking valid config
            if ((CbSecCom.Text == "") | (CbBaudRate.Text == "") | (CbDatabits.Text == "") | (CbParity.Text == "") | (CbStopbits.Text == ""))
            {
                //CbSecCom .Text  = "";
                MessageBox.Show("Oh I found some mistakes ,Please config correctly OR you can cancel form !");
            }
            else
            {
                //cancel form2 and transfer config  data to form1
                BKBIS.SelCom = CbSecCom.Text;
                int.TryParse(CbBaudRate.Text, out BKBIS.Baudrate);
                int.TryParse(CbDatabits.Text, out BKBIS.Databits);
                Enum.TryParse(CbStopbits.Text, out BKBIS.Stopbits);
                Enum.TryParse(CbParity.Text, out BKBIS.Parity);
                Close();
            }

        }

        private void ButCancel_Click_1(object sender, EventArgs e)
        {
            BKBIS.SelCom = "";
            Close();
        }

        private void CbBaudRate_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void CbSecCom_SelectedIndexChanged(object sender, EventArgs e)
        {

        }   
    }
}